package com.nan.gbd.library.utils.usage;

import java.text.DecimalFormat;

public class Usage {
    long totalRxBytes;//总数据 下载字节
    long totalTxBytes;//总数据 上传字节
    long wifiTotalData;//wifi总流量数据
    long mobleTotalData;//移动总流量数据
    long mobleRxBytes;//移动 下载字节
    long mobleTxBytes;//移动 上传字节
    long wifiRxBytes;//wifi 下载字节
    long wifiTxBytes;//wifi 上传字节
    String uid;//包名


    @Override
    public String toString() {
        return "Usage{" +
                "totalRxBytes=" + totalRxBytes +
                ", totalTxBytes=" + totalTxBytes +
                ",wifi总流量数据: wifiTotalData=" + getFileSize(wifiTotalData) +
                ", mobleTotalData=" + mobleTotalData +
                ", mobleRxBytes=" + mobleRxBytes +
                ", mobleTxBytes=" + mobleTxBytes +
                ",wifi 下载字节: wifiRxBytes=" + getFileSize(wifiRxBytes) +
                ",wifi 上传字节: wifiTxBytes=" + getFileSize(wifiTxBytes) +
                ", uid='" + uid + '\'' +
                '}';
    }


    public static String getFileSize(long aDouble) {
        if (aDouble >= 1024) {
            aDouble = aDouble / 1024;
            if (aDouble >= 1024) {
                aDouble = aDouble / 1024;
                if (aDouble >= 1024) {
                    aDouble = aDouble / 1024;
                    return getDoubleString(aDouble) + " GB";
                } else {
                    return getDoubleString(aDouble) + " MB";
                }
            } else {
                return getDoubleString(aDouble) + " KB";
            }
        } else {
            return getDoubleString(aDouble) + " Byte";
        }
    }

    public static String getDoubleString(double number) {
        String numberStr;
        if (((int) number * 1000) == (int) (number * 1000)) {
            //如果是一个整数
            numberStr = String.valueOf((int) number);
        } else {
            DecimalFormat df = new DecimalFormat("######0.00");
            numberStr = df.format(number);
        }
        return numberStr;
    }

}
